package command;

/**
 * 调整设备参数命令
 */
public class AdjustCommand implements Command {
    private final AgriculturalDevice device;
    private final String newParams;
    private String oldParams; // 记录原始参数用于撤销
   //private static String previousParams; // 新增：记录上一次的参数

    public AdjustCommand(AgriculturalDevice device, String newParams) {
        this.device = device;
        this.newParams = newParams;
        this.oldParams = device.getCurrentParams();
    }

    @Override
    public void execute() {
        System.out.println("调整设备参数: " + device.getDeviceId() + ", 新参数: " + newParams);
       // previousParams = oldParams;//新增
        device.adjust(newParams);
    }

    @Override
    public void undo() {
        System.out.println("撤销参数调整: " + device.getDeviceId() + ", 恢复参数: " + oldParams);//previousParams); oldParams);
        device.adjust(oldParams);//previousParams);//oldParams);
    }
    // 新增方法获取新参数
    public String getNewParams() {
        return newParams;
    }

    // 新增方法获取旧参数
    public String getOldParams() {
        return oldParams;
    }
}

